﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.HealthyWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.HealthyWay
{
    public class ShowHealthysCommandHandler : IRequestHandler<ShowHealthysCommand,ApiResult<List<Healthys>>>
    {
        IBaseReponsitory<Healthys> Healthys;

        public ShowHealthysCommandHandler(IBaseReponsitory<Healthys> Healthys)
        {
            this.Healthys = Healthys;
        }

        public async Task<ApiResult<List<Healthys>>> Handle(ShowHealthysCommand request, CancellationToken cancellationToken)
        {
            var list =await Healthys.GetQuery().Where(c => c.Rabit_Batch == request.Batch&&!c.IsDel).ToListAsync();
            if (list.Count > 0)
            {
                return new ApiResult<List<Healthys>>
                {
                    Code = ApiEnum.Success,
                    Message = "显示成功了",
                    Data = list
                };
            }
            else 
            {
                return new ApiResult<List<Healthys>>
                {
                    Code = ApiEnum.False,
                    Message = "请设置信息",
                };
            }
        }
    }
}
